import React from 'react';
import ReactDOM from 'react-dom/client';
import {App} from './App';
import {ConfigProvider, theme} from "antd";
import {designPage} from "plain-design-composition";
import {PageThemeUtils} from "./PageThemeUtils";
import '../module/index';
import {Application, ClientZoom} from "../../packages";
import zhcn from 'antd/locale/zh_CN';
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";

PageThemeUtils.state.zoom != null && ClientZoom.set(PageThemeUtils.state.zoom);

dayjs.locale("zh-cn");

// Switch.use.options.props.trueValue.default = 'Y'
// Switch.use.options.props.falseValue.default = 'N'

const Main = designPage(() => {
  return () => {

    const { dark, primary, shape, small } = PageThemeUtils.configuration.value;
    const token = {} as any;
    !!primary && (token.colorPrimary = primary);

    (Object.assign(token, shape != null ? {
      borderRadiusXS: 0,
      borderRadiusSM: 0,
      borderRadiusLG: 0,
      borderRadius: 0,
      borderRadiusOuter: 0,
    } : {}));

    !!small && shape == null && (token.borderRadius = 4);

    return (
      <ConfigProvider
        locale={zhcn}
        theme={{
          algorithm: [
            ...dark ? [theme.darkAlgorithm] : [],
            ...small ? [theme.compactAlgorithm] : [],
          ],
          token,
        }}>
        <Application locale={zhcn} theme={{ dark }}>
          <App/>
        </Application>
      </ConfigProvider>
    );
  };
});

ReactDOM.createRoot(document.getElementById('app') as HTMLElement).render(<Main/>);
